Ext.Loader.setConfig({
    enabled: true
});
Ext.Loader.setPath('Ext.ux', rootPath + '/res/extjs/ux/');
Ext.require(['Ext.data.*', 'Ext.grid.*', 'Ext.util.*',
    'Ext.form.field.ComboBox', 'Ext.form.FieldSet',
    'Ext.tip.QuickTipManager', 'Ext.ux.data.PagingMemoryProxy'

]);

var data, store, columns, queryGrid, pager;
Ext.onReady(function () {
    Ext.QuickTips.init();
    Ext.EventManager.onWindowResize(function () {
        queryGrid.getView().refresh();
    });
    initGrid();
});

/* init grid */
function initGrid() {
    // create the data store
    store = Ext.create('Ext.data.Store', {
        fields: [{
            name: 'recordId',
            type: 'auto'
        }, {
            name: 'bikeNum',
            type: 'auto'
        }, {
            name: 'beginTime',
            type: 'auto'
        }, {
            name: 'endTime',
            type: 'auto'
        }, {
            name: 'useTime',
            type: 'auto'
        }, {
            name: 'useAmount',
            type: 'auto'
        }, {
            name: 'useType',
            type: 'auto'
        }],
        remoteSort: true,
        pageSize: 10,
        proxy: {
            type: 'ajax',
            url: rootPath + '/user-bike/get-bike-by-user',
            reader: {
                type: 'json',
                root: 'rows',
                totalProperty: 'total'
            }
        }
    });
    // width确定的宽度
    //

    columns = [{
        text: '使用记录ID',
        sortable: false,
        dataIndex: 'recordId',
        align: 'center',
        tdCls: 'ver-mid'
    }, {
        text: '车牌号',
        width: 90,
        sortable: true,
        dataIndex: 'bikeNum',
        tdCls: 'ver-mid'
    }, {
        text: '开始时间',
        width: 90,
        sortable: true,
        dataIndex: 'beginTime',
        tdCls: 'ver-mid'
    }, {
        text: '结束时间',
        width: 90,
        sortable: true,
        dataIndex: 'endTime',
        tdCls: 'ver-mid'
    }, {
        text: '使用时间',
        width: 90,
        sortable: true,
        dataIndex: 'useTime',
        tdCls: 'ver-mid'
    }, {
        text: '使用金额',
        width: 90,
        sortable: true,
        dataIndex: 'useAmount',
        tdCls: 'ver-mid'
    }, {
        text: '使用类型',
        width: 90,
        sortable: true,
        dataIndex: 'useType',
        renderer: function (value) {
            var str = "";
            if (value == 1) {
                str = "使用中";
            } else if (value == 2) {
                str = "已结束使用";
            }
            return str;
        }
    }];
    // pager
    pager = Ext.create('Ext.PagingToolbar', {
        store: store,
        displayInfo: true,
        displayMsg: '显示第 {0} 条到 {1} 条记录,一共 {2} 条'
    });
    // create the Grid
    queryGrid = Ext.create('Ext.grid.Panel', {
        store: store,
        stateful: true,
        collapsible: false,
        multiSelect: true,
        stateId: 'stateGrid',
        columns: columns,
        // height: 300,
        renderTo: 'queryGrid',
        bbar: pager,
        viewConfig: {
            stripeRows: true,
            enableTextSelection: true,
            deferRowRender: false,
            forceFit: true,
            emptyText: "<font class='emptyText'>没有符合条件的记录</font>",
            autoScroll: true,
            scrollOffset: -10
        }
    });
    store.load();

}
